package com.ruoyi.omp.api.factory;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.omp.api.RemoteTrendService;
import com.ruoyi.omp.api.domain.TrendData;
import com.ruoyi.omp.api.domain.TrendType;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
@Slf4j
public class RemoteTrendFactory implements FallbackFactory<RemoteTrendService> {
    @Override
    public RemoteTrendService create(Throwable throwable) {
        log.error("趋势图数据服务调用失败:{}", throwable.getMessage());
        return new RemoteTrendService() {

            @Override
            public R addTrendData(TrendData trendData) {
                return R.fail("添加趋势数据失败:" + throwable.getMessage());
            }

            @Override
            public R addTrendType(TrendType trendType) {
                return R.fail("获取趋势类型:" + throwable.getMessage());
            }

            @Override
            public R<List<Map<String, Object>>> execSql(String sqlStr) {
                return R.fail("执行sql字符串失败:" + throwable.getMessage());
            }

            @Override
            public R<Map<String, String>> getTrendDataByType(String type, Integer limit) {
                return R.fail("获取趋势数据失败:" + throwable.getMessage());
            }

            @Override
            public R<List<TrendData>> selectTrendDataByType(String type) {
                return R.fail("获取趋势数据列表失败:" + throwable.getMessage());
            }

            @Override
            public R<TrendData> getTrendDataByTypeAndKey(String trendType, String key) {
                return R.fail("获取趋势key数据失败:" + throwable.getMessage());
            }

            @Override
            public R updateTrendDataValue(String trendType,String key, String dataValue) {
                return R.fail("更新趋势数据值失败:" + throwable.getMessage());
            }


/*            @Override
            public R getTrendTypeData(String type) {
                return R.fail("获取趋势数据失败:" + throwable.getMessage());
            }*/
        };
    }
}
